package Undefinied;

import org.newdawn.slick.GameContainer;
import org.newdawn.slick.Graphics;
import org.newdawn.slick.Image;
import org.newdawn.slick.MouseListener;
import org.newdawn.slick.SlickException;
import org.newdawn.slick.geom.Rectangle;
import org.newdawn.slick.gui.AbstractComponent;
import org.newdawn.slick.gui.ComponentListener;
import org.newdawn.slick.state.StateBasedGame;
/**
*@authors:Eric Heinz
*@since 05.07.2011,17:23:43
*@info Die Klasse Zeigt einen Layer aus Tiles an
*/

public class Layer extends Anzeigbar {
	static final String Pfad="";//"D:\\DropBox\\Dropbox\\MetroidProject\\MetroidProject\\";
	public Image img;
	public Rectangle rect;
	public Image[]tileArray ;
	public int[][]Array;
	public Boolean Ausgewhlt=true;
	public int tilesize=16;
	
	Layer(){
		this.XRange=15*16;
		this.YRange=15*16;
		
		try {
			img=new Image(Pfad+"data\\Tiles\\aqa.bmp");
			int x=img.getHeight()/16;
			int y=img.getWidth()/16;
			int d=(x+1)*(y+1);
			int m=0;
			tileArray=new Image[d];
			Array=new int[255][255]; 
			
			for(int i=0;i<=XRange/tilesize;i++){
				for(int j=0;j<=YRange/tilesize;j++){
					tileArray[m]=img.getSubImage(i*16, j*16, 16,16);
					Array[i][j]=0;
					
					m++;
				}
			}
			img.getGraphics().clear();
			
		} catch (SlickException e) {
			e.printStackTrace();
		}
		
		remaster();
		
	}
	
	public void init(GameContainer gc, StateBasedGame sbg) {
	
	}


	public void remaster(){
		int m;
		Graphics g;
		try {
			g = img.getGraphics();
			g.clear();
		
			for(int i=0;i<=XRange/tilesize;i++){
				for(int j=0;j<=YRange/tilesize;j++){
					m=Array[i][j];
					if(m!=0){
						g.translate(i*16, j*16);
						tileArray[m].draw();
						g.resetTransform();
					}	

				}
			}
			g.flush();

		
		} catch (SlickException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
	}
	

	public void render(GameContainer gc, StateBasedGame sbg, Graphics gg) {
		img.draw();
	}



	public void update(GameContainer container, StateBasedGame sbg, int delta) {
		// TODO Auto-generated method stub
		
	}





}
